<template>
  <div>
    <!-- 全局顶部深色标题栏 -->
    <div class="global-header-bar">
      <div class="global-header-title">网格化治理平台</div>
      <div class="global-header-user">
        <el-icon class="user-icon">
          <User />
        </el-icon>
        <span class="user-name">{{ userName }}</span>
        <el-button type="primary" size="small" class="logout-btn" @click="handleLogout">退出</el-button>
      </div>
    </div>
    <el-container>
      <el-aside max-width="2000px">
        <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" default-active="2"
          text-color="#fff" router style="height: 1500px;width: 200px;">

          <!-- <el-menu-item index="/DangerousList">
          <el-icon><icon-menu /></el-icon>
          <span>事故列表</span>
        </el-menu-item>
        <el-menu-item index="/AddDangerous">
          <el-icon><icon-menu /></el-icon>
          <span>事故添加</span>
        </el-menu-item>
        <el-menu-item index="/AddCarView">
          <el-icon><icon-menu /></el-icon>
          <span>车辆添加</span>
        </el-menu-item>
        <el-menu-item index="/AddPeopleView">
          <el-icon><document /></el-icon>
          <span>事故人添加</span>
        </el-menu-item> -->

          <el-sub-menu index="1">
            <template #title>
              <el-icon>
                <Expand />
              </el-icon>
              <span>流程引擎</span>
            </template>
            <el-menu-item index="/FormTypeInfo/FromTypeInfoList">
              <el-icon><icon-menu /></el-icon>
              <span>表单分类管理</span>
            </el-menu-item>
            <el-menu-item index="/FormInfo/FormAdmin">
              <el-icon><icon-menu /></el-icon>
              <span>表单管理</span>
            </el-menu-item>
            <el-menu-item index="/FormNode/FormNodeAdmin">
              <el-icon><icon-menu /></el-icon>
              <span>表单节点管理</span>
            </el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="2">
            <template #title>
              <el-icon>
                <Expand />
              </el-icon>
              <span>事件处理</span>
            </template>
            <el-menu-item index="/instance/create">
              <el-icon>
                <Setting />
              </el-icon>
              <span>创建应用</span>
            </el-menu-item>
            <el-menu-item index="/Instance/MyTodo">
              <el-icon>
                <Document />
              </el-icon>
              <span>我的表单</span>
            </el-menu-item>
            <el-menu-item index="/Instance/MyTodo">
              <el-icon>
                <Grid />
              </el-icon>
              <span>我的待办</span>
            </el-menu-item>
          </el-sub-menu>





        </el-menu>
      </el-aside>
      <el-main>
        <!-- 顶部标题栏（主内容区） -->

        <!-- 横向超链接导航 -->
        <div class="main-nav-links">
          <router-link to="/FormInfo/FormAdmin" class="main-link" active-class="main-link-active">表单页面</router-link>
          <router-link to="/FormNode/FormNodeAdmin" class="main-link" active-class="main-link-active">表单节点页面</router-link>
          <router-link to="/FormTypeInfo/FromTypeInfoList" class="main-link"
            active-class="main-link-active">表单分类页面</router-link>
          <router-link to="/instance/create" class="main-link" active-class="main-link-active">创建应用</router-link>
          <router-link to="/FormInfo/formNode" class="main-link" active-class="main-link-active">我的待办</router-link>
          <router-link to="/FormInfo/formList" class="main-link" active-class="main-link-active">我的表单</router-link>
        </div>
        <RouterView />
      </el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
  Promotion,
  Expand,
  Grid,
} from '@element-plus/icons-vue'
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessageBox } from 'element-plus';

import { useStore } from '@/stores/userInfo'//pinia


const user = useStore();

// 假设登录人姓名存储在localStorage或pinia等
const userName = ( user.userinfo.userName|| '未登录');


const router = useRouter();

const handleLogout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
    // 清理登录信息
    localStorage.removeItem('LoginName');
    localStorage.removeItem('Token');
    // 跳转到登录页
    router.push('/');
  });
};
</script>

<style scoped>
.global-header-bar {
  width: 100%;
  height: 54px;
  background: #3a4651;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  box-sizing: border-box;
}

.global-header-title {
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 2px;
}

.global-header-user {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  padding: 0 32px;
  height: 56px;
  margin-bottom: 0;
  box-sizing: border-box;
}

.header-title {
  font-size: 22px;
  font-weight: bold;
  color: #222;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-icon {
  color: #fff;
  font-size: 18px;
}

.user-name {
  font-size: 15px;
  color: #333;
}

.logout-btn {
  margin-left: 8px;
}

.main-nav-links {
  width: 100%;
  background: #f6fcff;
  border-bottom: 1px solid #e4e7ed;
  padding: 0 32px;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 32px;
  margin-bottom: 18px;
  box-sizing: border-box;
  justify-content: space-between;
}

.main-link {
  flex: 1;
  text-align: center;
  color: #337ecc;
  font-size: 15px;
  text-decoration: none;
  padding: 0 8px;
  line-height: 44px;
  transition: color 0.2s;
}

.main-link:hover {
  color: #409eff;
  text-decoration: underline;
}

.main-link-active {
  color: #409eff;
  font-weight: bold;
  border-bottom: 2px solid #409eff;
}
</style>